This article is for development with Visual Studio Code, a multi-platform source code editor developed by Microsoft. For development with "full" Visual Studio (Windows-only) IDE, see Getting Started under new .NET using IDE.
Open a command prompt.
Create a folder named Hello and navigate to the folder.
Type the following: dotnet new console. This command creates a project file (Hello.csproj) and a main program file (Program.cs).
Type the following: dotnet add package OpcLabs.QuickOpc. This command adds OPC Data Client package reference to the project file.
Type the following: code . (note the dot '.' as a parameter to the command.) Visual Studio Code starts and its window opens.
At this point, you might be asked "Required assets to build and debug are missing from 'vscode'. Add them?". If so, press the
button in the popup window.A notification will appear "There are unresolved dependencies from 'Hello.csproj'. Please execute the restore command to continue.". Press the
button in the popup window.In the Explorer window, click on the Program.cs file. The file opens in the code editor.
Add following code to the beginning of the Program.cs file:
using OpcLabs.EasyOpc.UA;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyUAClient(); object value = client.ReadValue( "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853"); Console.WriteLine(value);
Select F5) from the menu, or press the corresponding button on the toolbar.
-> (This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.
Open a command prompt.
Create a folder named HelloXml and navigate to the folder.
Type the following: dotnet new console. This command creates a project file (HelloXml.csproj) and a main program file (Program.cs).
Type the following: dotnet add package OpcLabs.QuickOpc. This command adds OPC Data Client package reference to the project file.
Type the following: code . (note the dot '.' as a parameter to the command.) Visual Studio Code starts and its window opens.
At this point, you might be asked "Required assets to build and debug are missing from 'vscode'. Add them?". If so, press the
button in the popup window.A notification will appear "There are unresolved dependencies from 'Hello.csproj'. Please execute the restore command to continue.". Press the
button in the popup window.In the Explorer window, click on the Program.cs file. The file opens in the code editor.
Add following code to the beginning of the Program.cs file:
using OpcLabs.EasyOpc.DataAccess;
In Program.cs, replace the body of the Main method by following code:
var client = new EasyDAClient(); object value = client.ReadItemValue( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double"); Console.WriteLine(value);
Select F5) from the menu, or press the corresponding button on the toolbar.
-> (This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.